package com.jiangxiaofei.citycloud.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.bean.MenuBean;
import com.jiangxiaofei.citycloud.event.MenuOnclickMessage;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by Administrator on 2017/9/4 0004.
 */

public class MeSettingMenuRecyAdapter extends RecyclerView.Adapter<MeSettingMenuRecyAdapter.MeSettingViewHolder> {
    List<MenuBean> menuList;
    Context mContext;
    String type;

    public MeSettingMenuRecyAdapter(List<MenuBean> menuList, Context mContext, String type) {
        this.menuList = menuList;
        this.mContext = mContext;
        this.type = type;
    }


    @Override
    public MeSettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.item_me_menu_layout, parent, false);
        MeSettingViewHolder viewHolder = new MeSettingViewHolder(v);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MeSettingViewHolder holder, int position) {
        holder.tvMenu.setText(menuList.get(position).getName());
        Glide.with(mContext).load(menuList.get(position).getResource()).into(holder.imgMenu);
    }

    @Override
    public int getItemCount() {
        return menuList.size();
    }


    class MeSettingViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView tvMenu;
        ImageView imgMenu;

        public MeSettingViewHolder(View itemView) {
            super(itemView);
            tvMenu = itemView.findViewById(R.id.me_tv_menu);
            imgMenu = itemView.findViewById(R.id.me_img_menu);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            EventBus.getDefault().post(new MenuOnclickMessage(getLayoutPosition(),type ));
        }
    }

}
